<template>
  <div class="project-status-container">
    <el-card class="status-card" shadow="hover">
      <div class="header">
        <div class="title-section">
          <h2 class="page-title">
            <el-icon class="title-icon"><TrendCharts /></el-icon>
            项目状态
            <el-tag v-if="projectData.project_name" type="primary" size="small" style="margin-left: 10px;">
              {{ projectData.project_name }}
            </el-tag>
          </h2>
          <p class="description">
            展示项目整体状态、进展、问题等
            <span v-if="projectData.project_id" style="color: #e6a23c; font-weight: 500;">
              (项目编号: {{ projectData.project_id }})
            </span>
          </p>
        </div>
        <el-button v-if="hasPermission" type="primary" @click="openDialog()" class="create-btn">
          <el-icon><Plus /></el-icon>
          添加状态
        </el-button>
      </div>

      <!-- 项目概览卡片 -->
      <div class="overview-section">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-card class="overview-card" shadow="hover">
              <div class="overview-item">
                <div class="overview-icon success">
                  <el-icon><CircleCheck /></el-icon>
                </div>
                <div class="overview-content">
                  <div class="overview-number">{{ statusCounts.normal }}</div>
                  <div class="overview-label">正常状态</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="overview-card" shadow="hover">
              <div class="overview-item">
                <div class="overview-icon warning">
                  <el-icon><Clock /></el-icon>
                </div>
                <div class="overview-content">
                  <div class="overview-number">{{ statusCounts.delayed }}</div>
                  <div class="overview-label">延期状态</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="overview-card" shadow="hover">
              <div class="overview-item">
                <div class="overview-icon info">
                  <el-icon><Document /></el-icon>
                </div>
                <div class="overview-content">
                  <div class="overview-number">{{ statusCounts.pending }}</div>
                  <div class="overview-label">待处理</div>
                </div>
              </div>
            </el-card>
          </el-col>
          <el-col :span="6">
            <el-card class="overview-card" shadow="hover">
              <div class="overview-item">
                <div class="overview-icon danger">
                  <el-icon><Warning /></el-icon>
                </div>
                <div class="overview-content">
                  <div class="overview-number">{{ statusCounts.risk }}</div>
                  <div class="overview-label">风险状态</div>
                </div>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>

      <!-- 搜索区域 -->
      <div class="search-section">
        <el-input
          v-model="searchKeyword"
          placeholder="搜索项目事项、状态说明..."
          class="search-input"
          clearable
        >
          <template #prefix>
            <el-icon><Search /></el-icon>
          </template>
        </el-input>
        <el-select v-model="filterStatus" placeholder="状态筛选" clearable>
          <el-option label="正常" value="正常" />
          <el-option label="正在运行" value="正在运行" />
          <el-option label="停止" value="停止" />
          <el-option label="警告" value="警告" />
        </el-select>
      </div>

      <!-- 项目状态表格 -->
      <div class="status-table-section mobile-table-card">
        <h3>项目状态详情</h3>
        
        <!-- 桌面端表格 -->
        <el-table :data="paginatedStatusList" stripe border v-loading="loading" class="desktop-table">
          <el-table-column prop="item_name" label="项目事项" min-width="150" />
          <el-table-column prop="status" label="状态" width="120">
            <template #default="scope">
              <el-tag :type="getStatusType(scope.row.status)" size="small">
                {{ scope.row.status }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="description" label="状态说明" min-width="200" show-overflow-tooltip />
          <el-table-column prop="support_department" label="支持部门" min-width="150" />
          <el-table-column prop="remark" label="备注" min-width="150" show-overflow-tooltip />
          <el-table-column label="操作" width="200" fixed="right" v-if="hasPermission">
            <template #default="scope">
              <el-button size="small" type="primary" @click="openDialog(scope.row)">
                <el-icon><Edit /></el-icon>
                编辑
              </el-button>
              <el-button v-if="canAdd" size="small" type="danger" @click="handleDelete(scope.row.id)">
                <el-icon><Delete /></el-icon>
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        
        <!-- 移动端卡片列表 -->
        <div class="mobile-card-list">
          <div 
            v-for="item in paginatedStatusList" 
            :key="item.id" 
            class="mobile-card-item"
          >
            <div class="item-row">
              <span class="item-label">项目事项:</span>
              <span class="item-value">{{ item.item_name }}</span>
            </div>
            <div class="item-row">
              <span class="item-label">状态:</span>
              <span class="item-value">
                <el-tag :type="getStatusType(item.status)" size="small">
                  {{ item.status }}
                </el-tag>
              </span>
            </div>
            <div class="item-row">
              <span class="item-label">状态说明:</span>
              <span class="item-value">{{ item.description }}</span>
            </div>
            <div class="item-row">
              <span class="item-label">支持部门:</span>
              <span class="item-value">{{ item.support_department }}</span>
            </div>
            <div class="item-row" v-if="item.remark">
              <span class="item-label">备注:</span>
              <span class="item-value">{{ item.remark }}</span>
            </div>
            <div class="item-row" v-if="hasPermission">
              <span class="item-label">操作:</span>
              <span class="item-value">
                <el-button size="small" type="primary" @click="openDialog(item)">
                  <el-icon><Edit /></el-icon>
                  编辑
                </el-button>
                <el-button v-if="canAdd" size="small" type="danger" @click="handleDelete(item.id)">
                  <el-icon><Delete /></el-icon>
                  删除
                </el-button>
              </span>
            </div>
          </div>
        </div>
        
        <!-- 分页组件 -->
        <div class="pagination-container">
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 50, 100]"
            :total="filteredStatusList.length"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            background
          />
        </div>
      </div>
    </el-card>

    <!-- 项目状态创建/编辑对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="form.id ? '编辑项目状态' : '添加项目状态'"
      :width="isMobile() ? '95%' : '700px'"
      align-center
      :close-on-click-modal="false"
      :top="isMobile() ? '5vh' : '15vh'"
    >
      <el-form :model="form" :rules="formRules" ref="formRef" :label-width="isMobile() ? '80px' : '120px'" :label-position="isMobile() ? 'top' : 'right'">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目编号" prop="project_id">
              <el-input v-model="form.project_id" placeholder="项目编号" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目事项" prop="item_name">
              <el-input v-model="form.item_name" placeholder="请选择项目事项" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="请选择状态" style="width: 100%">
                <el-option label="正常" value="正常" />
                <el-option label="正在运行" value="正在运行" />
                <el-option label="停止" value="停止" />
                <el-option label="警告" value="警告" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支持部门" prop="support_department">
              <el-input v-model="form.support_department" placeholder="请输入支持部门" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="状态说明" prop="description">
          <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请描述状态说明" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注信息（选填）" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="submitLoading">确认</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { TrendCharts, CircleCheck, Clock, Document, Warning, Plus, Search, Edit, Delete } from '@element-plus/icons-vue'
import { getProjectStatusListByProjectId,createProjectStatus, updateProjectStatus, deleteProjectStatus } from '../../api/projectStatus'
import { isMobile, getMobileDialogConfig, getMobileFormConfig } from '../../utils/mobile'

// 定义props
const props = defineProps({
  projectId: {
    type: String,
    default: ''
  },
  projectData: {
    type: Object,
    default: () => ({})
  }
})

// 获取当前登录用户信息
const currentUser = ref(JSON.parse(localStorage.getItem('user') || '{}'))
const isAdmin = computed(() => currentUser.value.userType === '管理员')

// 预定义的项目事项列表
const predefinedItems = [
  '合同签署', '深化设计', '设计变更', '人员', '订货', '设备到货', 
  '进场报验', '施工手续', '公司软件部署', '第三方软件部署', 
  '分包商施工', '施工质量', '施工进度', '安全隐患', '验收', 
  '收款', '分包商付款', '设备技术问题'
]

// 检查是否为当前项目的项目经理
const isProjectManager = computed(() => {
  if (!props.projectData || !props.projectData.project_manager) {
    return false
  }
  // 检查当前用户是否为该项目的项目经理
  return currentUser.value.username === props.projectData.project_manager || 
         currentUser.value.userId === props.projectData.project_manager ||
         currentUser.value.id === props.projectData.project_manager
})

// 检查是否有权限操作（只有当前项目的项目经理可以操作）
const hasPermission = computed(() => {
  return isProjectManager.value
})

// 检查是否为管理员（只有管理员可以新增）
const canAdd = computed(() => {
  return isAdmin.value
})

// 响应式数据
const projectStatusList = ref([])
const loading = ref(false)
const submitLoading = ref(false)
const dialogVisible = ref(false)
const searchKeyword = ref('')
const filterStatus = ref('')
const formRef = ref()

const form = ref({
  id: null,
  project_id: '',
  item_name: '',
  status: '',
  description: '',
  support_department: '',
  remark: ''
})

const formRules = {
  project_id: [{ required: true, message: '请输入项目编号', trigger: 'blur' }],
  item_name: [
    { required: true, message: '请选择项目事项', trigger: 'change' },
    { 
      validator: (rule, value, callback) => {
        if (!value || !form.value.status) {
          callback()
          return
        }
        
        const currentProjectId = props.projectData.project_id || props.projectId
        const existingItem = projectStatusList.value.find(status => 
          status.project_id === currentProjectId && 
          status.item_name === value && 
          status.status === form.value.status &&
          status.id !== form.value.id
        )
        
        if (existingItem) {
          callback(new Error('该项目事项的此状态已存在，请选择其他事项或状态'))
        } else {
          callback()
        }
      }, 
      trigger: 'change' 
    }
  ],
  status: [
    { required: true, message: '请选择状态', trigger: 'change' },
    { 
      validator: (rule, value, callback) => {
        if (!value || !form.value.item_name) {
          callback()
          return
        }
        
        const currentProjectId = props.projectData.project_id || props.projectId
        const existingItem = projectStatusList.value.find(status => 
          status.project_id === currentProjectId && 
          status.item_name === form.value.item_name && 
          status.status === value &&
          status.id !== form.value.id
        )
        
        if (existingItem) {
          callback(new Error('该项目事项的此状态已存在，请选择其他状态'))
        } else {
          callback()
        }
      }, 
      trigger: 'change' 
    }
  ],
  description: [{ required: true, message: '请输入状态说明', trigger: 'blur' }],
  support_department: [{ required: true, message: '请输入支持部门', trigger: 'blur' }]
}

// 状态统计
const statusCounts = computed(() => {
  const counts = {
    normal: 0,
    delayed: 0,
    pending: 0,
    risk: 0
  }
  
  // 只统计当前项目的状态
  const currentProjectId = props.projectData.project_id || props.projectId
  const currentProjectStatus = projectStatusList.value.filter(status => 
    status.project_id === currentProjectId
  )
  
  currentProjectStatus.forEach(item => {
    switch (item.status) {
      case '正常':
        counts.normal++
        break
      case '正在运行':
        counts.pending++
        break
      case '停止':
        counts.delayed++
        break
      case '警告':
        counts.risk++
        break
    }
  })
  
  return counts
})

// 可用项目事项（排除已存在的）
const availableItems = computed(() => {
  const currentProjectId = props.projectData.project_id || props.projectId
  const existingItems = projectStatusList.value
    .filter(status => status.project_id === currentProjectId)
    .map(status => status.item_name)
  
  // 如果是编辑模式，包含当前编辑的项目事项
  if (form.value.id && form.value.item_name) {
    return predefinedItems.filter(item => 
      !existingItems.includes(item) || item === form.value.item_name
    )
  }
  
  // 如果是新增模式，排除已存在的项目事项
  return predefinedItems.filter(item => !existingItems.includes(item))
})

// 过滤后的状态列表
const filteredStatusList = computed(() => {
  const currentProjectId = props.projectData.project_id || props.projectId
  
  // 首先按项目ID过滤，确保只显示当前项目的状态
  let filtered = projectStatusList.value.filter(status => 
    status.project_id === currentProjectId
  )
  
  // 然后按搜索关键词过滤
  if (searchKeyword.value) {
    const keyword = searchKeyword.value.toLowerCase()
    filtered = filtered.filter(status => 
      status.item_name.toLowerCase().includes(keyword) ||
      status.description.toLowerCase().includes(keyword)
    )
  }
  
  // 最后按状态过滤
  if (filterStatus.value) {
    filtered = filtered.filter(status => status.status === filterStatus.value)
  }
  
  return filtered
})

// 分页相关数据
const currentPage = ref(1)
const pageSize = ref(10)

// 分页后的状态列表
const paginatedStatusList = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return filteredStatusList.value.slice(start, end)
})

// 获取状态标签类型
function getStatusType(status) {
  const statusMap = {
    '正常': 'success',
    '正在运行': 'primary',
    '停止': 'info',
    '警告': 'warning'
  }
  return statusMap[status] || 'info'
}

// 生成32位GUID
function generateGUID() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    const r = Math.random() * 16 | 0
    const v = c === 'x' ? r : (r & 0x3 | 0x8)
    return v.toString(16)
  }).replace(/-/g, '')
}

// 打开对话框
function openDialog(status = null) {
  if (status) {
    // 编辑模式：复制状态数据
    form.value = { ...status }
    console.log('编辑模式，表单数据:', form.value)
  } else {
    // 新增模式：初始化表单
    form.value = {
      id: null,
      project_id: props.projectData.project_id || props.projectId || '',
      item_name: '',
      status: '',
      description: '',
      support_department: '',
      remark: ''
    }
    console.log('新增模式，表单数据:', form.value)
  }
  dialogVisible.value = true
}

// 提交表单
async function handleSubmit() {
  if (!formRef.value) return
  
  try {
    await formRef.value.validate(async (valid) => {
      if (!valid) return
      
      // 验证项目事项是否为空
      if (!form.value.item_name || form.value.item_name.trim() === '') {
        ElMessage.error('请选择项目事项')
        return
      }
      
      submitLoading.value = true
      
      if (!form.value.id) {
        // 创建项目状态时自动生成GUID
        const payload = { ...form.value }
        payload.id = generateGUID()
        console.log('创建项目状态，payload:', payload)
        await createProjectStatus(payload)
        ElMessage.success('项目状态添加成功')
      } else {
        // 更新项目状态
        console.log('更新项目状态，payload:', form.value)
        await updateProjectStatus(form.value.id, form.value)
        ElMessage.success('项目状态更新成功')
      }
      
      dialogVisible.value = false
      loadProjectStatus()
    })
  } catch (error) {
    ElMessage.error('操作失败，请重试')
    console.error('提交失败:', error)
  } finally {
    submitLoading.value = false
  }
}

// 删除项目状态
function handleDelete(id) {
  ElMessageBox.confirm('确认删除该项目状态？此操作不可恢复', '警告', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async () => {
    try {
      await deleteProjectStatus(id)
      ElMessage.success('删除成功')
      loadProjectStatus()
    } catch (error) {
      ElMessage.error('删除失败，请重试')
      console.error('删除失败:', error)
    }
  }).catch(() => {})
}

// 自动生成默认状态列表
async function generateDefaultStatus() {
  const currentProjectId = props.projectData.project_id || props.projectId
  if (!currentProjectId) return
  
  try {
    // 检查是否已有状态数据
    const params = { filter: `project_id:eq:${currentProjectId}` }
    const res = await getProjectStatusListByProjectId(currentProjectId)
    const existingStatus = Array.isArray(res) ? res : []
    
    // 过滤当前项目的数据
    const currentProjectStatus = existingStatus.filter(item => item.project_id === currentProjectId)
    console.log('当前项目已有状态数量:', currentProjectStatus.length)
    
    // 找出缺失的状态项（检查项目编号+状态组合是否已存在）
    const missingItems = []
    for (const item of predefinedItems) {
      // 检查该项目事项的"正常"状态是否已存在
      const existingItem = currentProjectStatus.find(status => 
        status.item_name === item
      )
      if (!existingItem) {
        missingItems.push(item)
      }
    }
    
    if (missingItems.length === 0) {
      console.log('所有状态项都已存在，跳过自动生成')
      return
    }
    
    // 生成缺失的默认状态列表
    console.log('开始生成缺失的状态项，项目ID:', currentProjectId, '缺失项:', missingItems)
    const defaultStatusList = missingItems.map(item => ({
      id: generateGUID(),
      project_id: currentProjectId,
      item_name: item,
      status: '正常',
      description: `${item}状态正常`,
      support_department: '待定',
      remark: '系统自动生成'
    }))
    
    // 批量创建状态
    let successCount = 0
    for (const status of defaultStatusList) {
      try {
        await createProjectStatus(status)
        successCount++
        console.log(`创建状态: ${status.item_name}`)
      } catch (error) {
        console.error(`创建状态失败: ${status.item_name}`, error)
      }
    }
    
    if (successCount > 0) {
      ElMessage.success(`已自动生成${successCount}个缺失的项目状态`)
    }
    console.log('默认状态列表生成完成')
  } catch (error) {
    console.error('生成默认状态列表失败:', error)
  }
}

// 加载项目状态列表
async function loadProjectStatus() {
  loading.value = true
  try {
    const params = {}
    const currentProjectId = props.projectData.project_id || props.projectId
    
    // 必须有项目编号才加载项目状态
    if (currentProjectId) {
      params.filter = `project_id:eq:${currentProjectId}`
      console.log('加载项目状态，项目ID:', currentProjectId)
      
      const res = await getProjectStatusListByProjectId(currentProjectId)
      const allStatus = Array.isArray(res) ? res : []
      
      // 过滤当前项目的数据
      projectStatusList.value = allStatus
      console.log('当前项目状态数量:', projectStatusList.value.length)
      
      // 检查是否需要生成默认状态
      const existingItems = projectStatusList.value.map(status => status.item_name)
      console.log('当前项目状态列表:', existingItems)
      const missingItems = predefinedItems.filter(item => !existingItems.includes(item))
      console.log('当前项目未有状态列表:', missingItems)
      if (missingItems.length > 0) {
        console.log('发现缺失的项目事项，开始生成默认状态，缺失项:', missingItems)
        // 生成默认状态
        await generateDefaultStatus()
        // 重新加载数据
        const newRes = await getProjectStatusListByProjectId(currentProjectId)
        console.log('生成默认状态后，当前项目状态列表:', newRes)
      // const newAllStatus = Array.isArray(newRes) ? newRes : []
        projectStatusList.value = newRes
        console.log('生成默认状态后，当前项目状态数量:', projectStatusList.value.length)
      } else {
        console.log('所有预定义项目事项都已存在，无需生成默认状态')
      }
    } else {
      // 没有项目编号时，不显示任何项目状态
      projectStatusList.value = []
      console.log('没有项目编号，不加载项目状态')
    }
  } catch (error) {
    ElMessage.error('加载项目状态失败')
    console.error('加载项目状态失败:', error)
    // 出错时也要设置为空数组，不影响其他页面
    projectStatusList.value = []
  } finally {
    loading.value = false
  }
}

// 监听项目数据变化
watch(() => props.projectData, (newProjectData) => {
  if (newProjectData && newProjectData.project_id) {
    // 如果当前正在编辑且项目编号为空，则自动填充
    if (dialogVisible.value && !form.value.project_id) {
      form.value.project_id = newProjectData.project_id
    }
    // 重新加载项目状态列表
    loadProjectStatus()
  }
}, { deep: true })

// 监听项目ID变化
watch(() => props.projectId, (newProjectId) => {
  if (newProjectId) {
    console.log('项目ID变化，重新加载项目状态:', newProjectId)
    loadProjectStatus()
  }
})

onMounted(() => {
  // 使用try-catch确保不影响其他页面
  try {
    loadProjectStatus()
  } catch (error) {
    console.error('项目状态页面初始化失败:', error)
    // 不显示错误消息，避免影响用户体验
  }
})
</script>

<style scoped>
.project-status-container {
  padding: 20px;
  background: #f5f7fa;
  min-height: calc(100vh - 120px);
}

.status-card {
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #ebeef5;
}

.title-section {
  flex: 1;
}

.create-btn {
  padding: 12px 20px;
  font-weight: 500;
  border-radius: 8px;
}

.page-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #303133;
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-icon {
  font-size: 24px;
  color: #409eff;
}

.description {
  margin: 0;
  font-size: 14px;
  color: #909399;
  line-height: 1.5;
}

.overview-section {
  margin-bottom: 30px;
}

.search-section {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  align-items: center;
}

.search-input {
  flex: 1;
  max-width: 300px;
}

.overview-card {
  border-radius: 8px;
}

.overview-item {
  display: flex;
  align-items: center;
  gap: 16px;
}

.overview-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.overview-icon.success { background: #67c23a; }
.overview-icon.warning { background: #e6a23c; }
.overview-icon.info { background: #409eff; }
.overview-icon.danger { background: #f56c6c; }

.overview-content {
  flex: 1;
}

.overview-number {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  line-height: 1;
}

.overview-label {
  font-size: 14px;
  color: #909399;
  margin-top: 4px;
}

.status-table-section {
  margin-top: 30px;
}

.status-table-section h3 {
  margin-bottom: 16px;
  color: #303133;
}

/* 移动端适配样式 */
@media screen and (max-width: 768px) {
  .project-status-container {
    padding: 10px;
  }
  
  .header {
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
  }
  
  .create-btn {
    width: 100%;
    margin-top: 10px;
  }
  
  .page-title {
    font-size: 20px;
    flex-wrap: wrap;
  }
  
  .overview-section .el-col {
    margin-bottom: 10px;
  }
  
  .overview-item {
    gap: 10px;
  }
  
  .overview-icon {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }
  
  .overview-number {
    font-size: 20px;
  }
  
  .overview-label {
    font-size: 12px;
  }
  
  .search-section {
    flex-direction: column;
    gap: 10px;
  }
  
  .search-input {
    max-width: 100%;
  }
  
  /* 隐藏桌面端表格，显示移动端卡片 */
  .mobile-table-card .desktop-table {
    display: none;
  }
  
  .mobile-table-card .mobile-card-list {
    display: block;
  }
  
  .mobile-card-item {
    background: #fff;
    border: 1px solid #ebeef5;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-card-item .item-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    gap: 10px;
  }
  
  .mobile-card-item .item-row:last-child {
    margin-bottom: 0;
  }
  
  .mobile-card-item .item-label {
    font-weight: 500;
    color: #606266;
    min-width: 80px;
    flex-shrink: 0;
  }
  
  .mobile-card-item .item-value {
    flex: 1;
    text-align: right;
    word-break: break-word;
  }
  
  .mobile-card-item .item-value .el-button {
    margin-left: 5px;
  }
  
  /* 调整对话框 */
  .el-dialog {
    width: 95% !important;
    margin: 5vh auto !important;
  }
  
  .el-dialog .el-form-item {
    margin-bottom: 15px;
  }
  
  .el-dialog .el-form-item__label {
    font-size: 14px;
    line-height: 1.2;
  }
  
  .el-dialog .el-input,
  .el-dialog .el-select {
    width: 100%;
  }
}

/* 超小屏幕适配 */
@media screen and (max-width: 480px) {
  .project-status-container {
    padding: 5px;
  }
  
  .page-title {
    font-size: 18px;
  }
  
  .description {
    font-size: 12px;
  }
  
  .overview-icon {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }
  
  .overview-number {
    font-size: 16px;
  }
  
  .overview-label {
    font-size: 11px;
  }
  
  .mobile-card-item {
    padding: 12px;
  }
  
  .mobile-card-item .item-row {
    margin-bottom: 8px;
  }
  
  .mobile-card-item .item-label {
    min-width: 70px;
    font-size: 12px;
  }
  
  .mobile-card-item .item-value {
    font-size: 12px;
  }
}

/* 桌面端显示表格，隐藏卡片 */
@media screen and (min-width: 769px) {
  .mobile-table-card .desktop-table {
    display: table;
  }
  
  .mobile-table-card .mobile-card-list {
    display: none;
  }
}
</style> 